package net.csdn.business.common;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;

import java.io.File;


class OpenatomCommonApplicationTests {

    void contextLoads() {
    }

    public static void main(String[] args) {
        // Endpoint以杭州为例，其它Region请按实际情况填写。
        String endpoint = "oss-cn-beijing.aliyuncs.com";
        // 填写步骤五获取的临时访问密钥（AccessKey ID和AccessKey Secret）。
        String accessKeyId = "STS.NV5XwyzHd7wWmm2Vre6SaNk6f";
        String accessKeySecret = "sJmWPEWBcxLL42D6rcVfH2mX9BB9cQHrN1KHrGwYLXu";
        // 填写步骤五获取的安全令牌SecurityToken。
        String securityToken = "CAIS8gF1q6Ft5B2yfSjIr5WAE83Nl5dFgLW8b0uDsnIwOtxNoa6dhDz2IHxFfnRuCeodvvs3lWtU6/8dlq56V5hASk3YNTqaHUmiqVHPWZHInuDox55m4cTXNAr+Ihr/29CoEIedZdjBe/CrRknZnytou9XTfimjWFrXWv/gy+QQDLItUxK/cCBNCfpPOwJms7V6D3bKMuu3OROY6Qi5TmgQ41Yl1j0ksf/gmZbHtEqG0GeXkLFF+97DRbG/dNRpMZtFVNO44fd7bKKp0lQLt0kQqfkm1vcUpm+W5Y3AWgZLhxKePuzd7tpqaRRlfbi23gv6eDpW/xqAAXxcx/gCa/U0D72e69qOrKyshVoTD9Vpd7IHXJzFJyKHxxp9Itq8SZdyJV61Vh0PupTbHX16nD2We3THebIvbq79Jjd8yAlnN7ngCOz5hhZ6mlaCnjRJXopkPSa3LM1DXptGWFltyVorHDFK7Ga7qdWDIgtSTgg7osiiiARi303e";

        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret, securityToken);
        // 将本地文件exampletest.txt上传至目标存储空间examplebucket下的目录exampledir。
        PutObjectRequest putObjectRequest = new PutObjectRequest("atomgit", "uploads/banner/banner.png", new File("/Users/zhangyl/Downloads/banner.png"));
        //PutObjectRequest putObjectRequest = new PutObjectRequest("atomgit", "uploads/assets/qrcode.png", new File("/Users/zhangyl/Downloads/assets/qrcode.png"));
        // 如果需要上传时设置存储类型与访问权限，请参考以下示例代码。
        // ObjectMetadata metadata = new ObjectMetadata();
        // metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.Standard.toString());
        // metadata.setObjectAcl(CannedAccessControlList.Private);
        // putObjectRequest.setMetadata(metadata);

        // 上传文件。
        ossClient.putObject(putObjectRequest);

        // 关闭OSSClient。
        ossClient.shutdown();
    }

}
